<template>

  <div class="checkout">
    <van-cell-group>
      <van-cell title="我的收藏" v-if="type == 'favorite'"/>
      <van-cell title="我的足迹" v-if="type == 'track'"/>
    </van-cell-group>
    <div v-for="item in cartList" :key="item.id" class="card-goods__item">
      <van-card :title="item.title" :desc="item.goods.descript" :num="item.count" :price="item.goods.price" :thumb="item.thumb">
      </van-card>
    </div>

  </div>
</template>

<script>
import utils from "@/utils/index.js";
import store from "@/utils/store.js";

export default {
  config: {
    navigationBarTitleText: "商品列表"
  },
  data() {
    return {
      activeFooter: 2,
      checkedGoods: [],
      checkeAllCarts: [],
      cartList: [],
      checkedAll: true,
      addr: undefined,
      message: "",
      idCarts: "",
      type: ""
    };
  },

  onLoad(options) {
    this.type = options.type;
  },
  onShow() {
    this.init();
  },
  computed: {

  },
  methods: {
    init() {
      let url = '/user/' + this.type + '/getListTop50'
      this.$API
        .get(url)
        .then(res => {
          
          let cartList = res.data;
          this.addr = res.data.addr;
          for (const index in cartList) {
            cartList[index].price = cartList[index].count * cartList[index].goods.price;
            cartList[index].thumb =
              utils.fileMgrUrl + cartList[index].goods.pic;
            cartList[index].goods.price = utils.formatPrice(cartList[index].goods.price)
            this.checkedGoods.push(cartList[index].id + "");
          }
          this.cartList = cartList;
        });
    },

    checkAll() {
      if (this.checkedGoods.length === this.cartList.length) {
        this.checkeAllCarts = this.checkedGoods;
        this.checkedGoods = [];
      } else {
        this.checkedGoods = this.checkeAllCarts;
      }
    },
    chooseAddress() {
      const url = "/pages/address/index?choose=true";
      wx.navigateTo({ url });
    }
  }
};
</script>

<style>
.van-submit-bar {
  bottom: 48px;
}

.card-goods__item {
  margin-bottom: 20px;
}

/*.card-goods {*/
/*background-color: #fff;*/

/*&__item {*/
/*position: relative;*/
/*background-color: #fafafa;*/

/*.van-checkbox__label {*/
/*width: 100%;*/
/*height: auto; // temp*/
/*padding: 0 10px 0 15px;*/
/*box-sizing: border-box;*/
/*}*/

/*.van-checkbox__icon {*/
/*top: 50%;*/
/*left: 10px;*/
/*z-index: 1;*/
/*position: absolute;*/
/*margin-top: -10px;*/
/*}*/

/*.van-card__price {*/
/*color: #f44;*/
/*}*/
/*}*/
/*}*/
</style>
